package com.qezhhnjy.flink.mapper;

import com.qezhhnjy.flink.bean.SensorReading;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommand;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisCommandDescription;
import org.apache.flink.streaming.connectors.redis.common.mapper.RedisMapper;

/**
 * @author zhaoyangfu
 * @date 2021/8/27-17:20
 */
public class MyRedisMapper implements RedisMapper<SensorReading> {
    @Override
    public RedisCommandDescription getCommandDescription() {
        return new RedisCommandDescription(RedisCommand.HSET, "sensor_temp");
    }

    @Override
    public String getKeyFromData(SensorReading sensorReading) {
        return sensorReading.getName();
    }

    @Override
    public String getValueFromData(SensorReading sensorReading) {
        return String.valueOf(sensorReading.getTemp());
    }
}
